<template>
  <div style="overflow: hidden; min-height: 188px">
    <div class="header" ref="header">
      <titles :title="props.info.text" />
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <div style="margin-top: 20px">
        <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="93" />
      </div>
    </div>
  </div>

  <div class="box-item">
    <div
      @click="pathChild(props.info, 0)"
      class="left-box"
      ref="leftBox"
      @mouseenter="imgEnter(0, props.info.children)"
      @mouseleave="imgLeave(0, props.info.children)"
      style="cursor: pointer"
    >
      <img
        class="item-left"
        :class="'leftTitle' + props.info.children[0].id"
        :src="urls + props.info.children[0].value + '?imageView2/1/w/410/h/548/format/webp'"
        alt=""
        v-if="props.info.children[0].value"
      />
      <div v-else class="item-left" :class="'leftTitle' + props.info.children[0].id">
        <UnitImageNull></UnitImageNull>
      </div>
      <!-- <img src="http://101.34.143.36:8890/api/image/387939155165253/h_548,w_410" alt="" v-else /> -->
      <div class="shadow" :class="'shadow' + props.info.children[0].id"></div>
    </div>
    <div class="content-box" ref="contentBox">
      <div
        class="child-item1"
        @mouseenter="imgEnter(0, props.info.children)"
        @mouseleave="imgLeave(0, props.info.children)"
        style="cursor: pointer"
      >
        <div class="child-title-box" :class="'child-item1' + props.info.children[0].id">
          <span @click="pathChild(props.info, 0)" class="child-title">{{ props.info.children[0].text }}</span>
          <div class="subTitle unit-subTitle" v-if="props.info.children[0].subTitle">
            ——{{ props.info.children[0].subTitle }}
          </div>
        </div>
        <span
          class="left-title"
          @click="pathChild(props.info, 0)"
          :style="{
            fontSize: store.styleInfo.contentSize,

            color: store.styleInfo.fontColor,
          }"
          >{{ props.info.children[0].remarks }}</span
        >
      </div>
      <div
        class="child-item2"
        @mouseenter="imgEnter(1, props.info.children)"
        @mouseleave="imgLeave(1, props.info.children)"
        style="cursor: pointer"
      >
        <div class="child-title-box" :class="'child-item1' + props.info.children[1].id">
          <span
            @click="pathChild(props.info, 1)"
            class="child-title"
            :style="{
              color: store.styleInfo.fontColor,
            }"
            >{{ props.info.children[1].text }}</span
          >
          <div class="subTitle unit-subTitle" v-if="props.info.children[1].subTitle">
            ——{{ props.info.children[1].subTitle }}
          </div>
        </div>
        <span
          @click="pathChild(props.info, 1)"
          class="left-title"
          :style="{
            fontSize: store.styleInfo.contentSize,

            color: store.styleInfo.fontColor,
          }"
          >{{ props.info.children[1].remarks }}</span
        >
      </div>
    </div>
    <div
      class="right-box"
      ref="rightBox"
      @click="pathChild(props.info.children, 1)"
      @mouseenter="imgEnter(1, props.info.children)"
      @mouseleave="imgLeave(1, props.info.children)"
      style="cursor: pointer"
    >
      <img
        class="item-left"
        :class="'leftTitle' + props.info.children[1].id"
        :src="urls + props.info.children[1].value + '?imageView2/1/w/410/h/548/format/webp'"
        alt=""
        v-if="props.info.children[1].value"
      />
      <div v-else class="item-left" :class="'leftTitle' + props.info.children[1].id">
        <UnitImageNull></UnitImageNull>
      </div>
      <!-- <img src="http://101.34.143.36:8890/api/image/387939155165253/h_548,w_410" alt="" v-else /> -->
      <div class="shadow" :class="'shadow' + props.info.children[1].id"></div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax2.vue';
import { onMounted, ref } from 'vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const header = ref(null);
const router = useRouter();
const route = useRoute();
const store = useProjectStore();
const rightBox = ref(null);
const leftBox = ref(null);
const contentBox = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
});
const pathChild = (e: any, index: number) => {
  //console.log(e);

  store.setchildModel(e);
  store.setCurrent(index);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { current: index, childId: props.info.id },
  });
};
const imgEnter = (index: number, list: any) => {
  let itemLeft = document.querySelectorAll(`.leftTitle${list[index].id}`)[0];
  let shadow = document.querySelectorAll(`.shadow${list[index].id}`)[0];
  let childItem1 = document.querySelectorAll(`.child-item1${list[index].id}`)[0];
  itemLeft.style.transform = 'scale(1.1)';
  shadow.style.backgroundColor = 'rgba(0, 0, 0, 0.4)';
  childItem1.style.paddingLeft = '12px';
};
const imgLeave = (index: number, list: any) => {
  let itemLeft = document.querySelectorAll(`.leftTitle${list[index].id}`)[0];
  let shadow = document.querySelectorAll(`.shadow${list[index].id}`)[0];
  let childItem1 = document.querySelectorAll(`.child-item1${list[index].id}`)[0];
  itemLeft.style.transform = 'scale(1)';
  shadow.style.backgroundColor = 'rgba(0, 0, 0, 0)';
  childItem1.style.paddingLeft = '0px';
};
onMounted(() => {
  animation();
  animation1();
});
const animation = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        //console.log('c', header.value);
        header.value.classList.add('animation-box7');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (header.value) {
        //   header.value.classList.remove('animation-box7');
        // }
      }
    });
  });
  observer.observe(header.value);
};
const animation1 = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        //console.log('c', header.value);
        contentBox.value.classList.add('animation-box6');
        rightBox.value.classList.add('animation-box3');
        leftBox.value.classList.add('animation-box2');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (contentBox.value && rightBox.value && leftBox.value) {
        //   contentBox.value.classList.remove('animation-box6');
        //   rightBox.value.classList.remove('animation-box3');
        //   leftBox.value.classList.remove('animation-box2');
        // }
      }
    });
  });
  observer.observe(contentBox.value);
};
</script>

<style lang="less" scoped>
@import './index.less';

.box-item {
  height: 748px;

  width: 100%;
  display: flex;
  justify-content: space-between;
}
.left-box {
  width: 410px;
  height: 548px;
  // margin-bottom: 120px;
  position: relative;
  overflow: hidden;
  img {
    width: 100%;
    height: 548px;
    transition: all 0.5s;
  }
  div {
    width: 410px;
    height: 548px;
    transition: all 0.5s;
  }
}

.content-box {
  width: 40%;
  padding: 50px;
}
.right-box {
  width: 410px;
  height: 548px;
  margin-top: 120px;
  position: relative;
  overflow: hidden;
  img {
    width: 410px;
    height: 548px;
    transition: all 0.5s;
  }
  div {
    width: 410px;
    height: 548px;
    transition: all 0.5s;
  }
}
.child-item1,
.child-item2 {
  display: flex;
  flex-direction: column;
  margin-top: 80px;
  cursor: pointer;
  font-size: 20px;
}
.child-item1 {
  margin-top: 120px;
}
.title {
  margin-top: 50px;
}
.child-title-box {
  box-shadow: inset 0px -1px 0px 0px #333333;
  margin-bottom: 12px;
  transition: all 0.5s;
  padding: 16px 0;
}
.child-title {
  display: flex;
  width: 100%;
  font-size: 20px;
  line-height: 30px;

  font-family: SourceHanSerifCN-Bold;

  transition: all 0.5s;
}
.header {
  width: 780px;
  min-height: 138px;
  margin: 0 auto;
  margin-bottom: 50px;
  margin-top: -138px;
  :deep(.tj) {
    line-height: 32px !important;
  }
}
.shadow {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.left-title {
  line-height: 32px;
}
.subTitle {
  text-align: center;
}
.unit-subTitle {
  text-align-last: left;
}
</style>
